import React, { Component } from 'react';
// 1- 引入context
import globalContext from "../context";
 class B extends Component {
  // 2- 创建一个名字为contextType的静态属性，值为globalContext
  static contextType = globalContext;
  render() {
      console.log(this.context)
      const {userName,age,changeUserName} = this.context;
      return (
          <div>
              <h3>B---得到的参数</h3>
              <button onClick={()=>{
                  changeUserName(userName+"b");
              }}>B---更改userName</button>
              <p>userName:{this.context.userName}|{userName}</p>
              <p>age:{this.context.age}|{age}</p>
          </div>
      );
  }
}
 export default B;